<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="申请人公司姓名" prop="sqrComName">
        <el-input
          v-model="queryParams.sqrComName"
          placeholder="请输入申请人公司姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="受益人公司姓名" prop="syrComName">
        <el-input
          v-model="queryParams.syrComName"
          placeholder="请输入受益人公司姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="单位性质" prop="dwXz">-->
<!--        <el-input-->
<!--          v-model="queryParams.dwXz"-->
<!--          placeholder="请输入单位性质"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="保函类型" prop="bhType">
        <el-select v-model="queryParams.bhType" placeholder="请选择保函类型" clearable>
          <el-option
            v-for="dict in dict.type.bh_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系人" prop="linkPerson">
        <el-input
          v-model="queryParams.linkPerson"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="ksrLinkFs">
        <el-input
          v-model="queryParams.ksrLinkFs"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="用户" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户" />
      </el-form-item>
      <el-form-item label="上级用户" prop="parentNickName">
        <el-input v-model="queryParams.parentNickName" placeholder="请输入上级用户" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
        <el-option
          v-for="dict in dict.type.finish_status"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="用户Id" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入用户Id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="父级用户Id" prop="parentUserId">-->
<!--        <el-input-->
<!--          v-model="queryParams.parentUserId"-->
<!--          placeholder="请输入父级用户Id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item label="时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:xx:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:xx:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:xx:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="2" class="total-count">
        <el-tag type="danger">总计: {{ total }} 条</el-tag>
      </el-col>

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:xx:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="xxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="id" align="center" prop="id" />-->


      <el-table-column label="用户" align="center" prop="nickName" />
      <el-table-column label="上级用户" align="center" prop="parentNickName" />
      <el-table-column label="申请人公司姓名" align="center" show-overflow-tooltip prop="sqrComName" />
      <el-table-column label="受益人公司姓名" align="center" show-overflow-tooltip  prop="syrComName" />
      <el-table-column label="项目名称" align="center" show-overflow-tooltip  prop="projectName" />
      <el-table-column label="联系人" align="center" prop="linkPerson" />
      <el-table-column label="联系方式" align="center" prop="ksrLinkFs" />
      <el-table-column label="保函类型" align="center" prop="bhType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bh_type" :value="scope.row.bhType"/>
        </template>
      </el-table-column>
      <el-table-column label="保函金额(万)" align="center" prop="bhJe" />
      <el-table-column label="保函期限" align="center" prop="bhQx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bhqx" :value="scope.row.bhQx"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.finish_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="合作合同" align="center" prop="htFj" />-->
<!--      <el-table-column label="招标文件" align="center" prop="zbwjFj" />-->
<!--      <el-table-column label="中标通知书" align="center" prop="zbtzFj" />-->
<!--      <el-table-column label="涉诉情况" align="center" prop="ssqk" />-->
      <el-table-column label="备注" align="center"  show-overflow-tooltip prop="remark" >
        <template slot-scope="scope">
          <el-tag   class="pointer-cursor"  @click="handleUpdateRemark(scope.row)" v-if="scope.row.remark" >{{ scope.row.remark }}</el-tag>
          <el-tag     class="pointer-cursor"  @click="handleUpdateRemark(scope.row)" v-else >无</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="createTime" />
<!--      <el-table-column label="用户Id" align="center" prop="userId" />-->
<!--      <el-table-column label="父级用户Id" align="center" prop="parentUserId" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:xx:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:xx:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <div v-if="title!='修改备注'">
        <el-form-item label="用户" prop="nickName" >
          <el-input v-model="form.nickName"  disabled placeholder="请输入用户" />
        </el-form-item>
        <el-form-item label="上级用户" prop="parentNickName">
          <el-input v-model="form.parentNickName" disabled placeholder="请输入上级用户" />
        </el-form-item>
        <el-form-item label="申请人公司姓名" prop="sqrComName">
          <el-input v-model="form.sqrComName" placeholder="请输入申请人公司姓名" />
        </el-form-item>
        <el-form-item label="受益人公司姓名" prop="syrComName">
          <el-input v-model="form.syrComName" placeholder="请输入受益人公司姓名" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="联系人" prop="linkPerson">
          <el-input v-model="form.linkPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="ksrLinkFs">
          <el-input v-model="form.ksrLinkFs" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="保函金额(万)" prop="bhJe">
          <el-input-number v-model="form.bhJe" placeholder="请输入保函金额" />
        </el-form-item>

        <el-form-item label="保函期限" prop="bhQx">
          <el-select v-model="form.bhQx" placeholder="请选择保函期限">
            <el-option
              v-for="dict in dict.type.bhqx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="保函类型" prop="bhType">
          <el-select v-model="form.bhType" placeholder="请选择保函类型">
            <el-option
              v-for="dict in dict.type.bh_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="合作合同" prop="htFj">
          <file-upload v-model="form.htFj"/>
        </el-form-item>
        <el-form-item label="招标文件" prop="zbwjFj">
          <file-upload v-model="form.zbwjFj"/>
        </el-form-item>
        <el-form-item label="中标通知书" prop="zbtzFj">
          <file-upload v-model="form.zbtzFj"/>
        </el-form-item>
        <el-form-item label="涉诉情况" prop="ssqk">
          <el-input v-model="form.ssqk" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.finish_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        </div>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="5" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listXx, getXx, delXx, addXx, updateXx } from "@/api/system/xx"
import {listUser} from "@/api/system/user";

export default {
  name: "Xx",
  dicts: ['bh_type','bhqx','finish_status'],
  data() {
    return {

      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信息管理表格数据
      xxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sqrComName: null,
        syrComName: null,
        projectName: null,
        dwXz: null,
        bhType: null,
        bhJe: null,
        bhQx: null,
        chYq: null,
        htFj: null,
        zbwjFj: null,
        zbtzFj: null,
        ssqk: null,
        fdbCs: null,
        ksrLinkFs: null,
        userId: null,
        parentUserId: null,
        nickName: null,
        parentNickName: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sqrComName: [
          { required: true, message: "申请人公司姓名不能为空", trigger: "blur" }
        ],
        syrComName: [
          { required: true, message: "受益人公司姓名不能为空", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        dwXz: [
          { required: true, message: "单位性质不能为空", trigger: "blur" }
        ],
        // bhType: [
        //   { required: true, message: "保函类型不能为空", trigger: "blur" }
        // ],
        bhJe: [
          { required: true, message: "保函金额不能为空", trigger: "blur" }
        ],
        bhQx: [
          { required: true, message: "保函期限不能为空", trigger: "blur" }
        ],
        chYq: [
          { required: true, message: "出函要求不能为空", trigger: "blur" }
        ],
        // htFj: [
        //   { required: true, message: "合作合同不能为空", trigger: "blur" }
        // ],
        // zbwjFj: [
        //   { required: true, message: "招标文件不能为空", trigger: "blur" }
        // ],
        // zbtzFj: [
        //   { required: true, message: "中标通知书不能为空", trigger: "blur" }
        // ],
        // ssqk: [
        //   { required: true, message: "涉诉情况不能为空", trigger: "blur" }
        // ],
        // fdbCs: [
        //   { required: true, message: "反担保措施不能为空", trigger: "blur" }
        // ],
        ksrLinkFs: [
          { required: true, message: "开函人联系方式不能为空", trigger: "blur" }
        ],
        linkPerson: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],




      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询信息管理列表 */
    getList() {
      this.loading = true
      listXx(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.xxList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sqrComName: null,
        syrComName: null,
        projectName: null,
        dwXz: null,
        dwZz: null,
        bhType: null,
        bhJe: null,
        bhQx: null,
        chYq: null,
        htFj: null,
        zbwjFj: null,
        zbtzFj: null,
        ssqk: null,
        fdbCs: null,
        ksrLinkFs: null,
        userId: null,
        parentUserId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        parentNickName: null,
        nickName: null,
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {

      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加信息管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getXx(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改信息管理"
      })
    },
    handleUpdateRemark(row) {
      this.reset()
      const id = row.id || this.ids
      getXx(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改备注"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateXx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addXx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delXx(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/xx/export', {
        ...this.queryParams
      }, `xx_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>.total-count {
  display: flex;
  align-items: center;
  justify-content: center;
}
.pointer-cursor {
  cursor: pointer;
}
</style>
